<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="org.jeecgframework.web.system.pojo.base.TSTerritory" %>
<%@ page import="org.jeecgframework.web.util.StaticValue" %>
<%@include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>申请备件</title>
    <script type="text/javascript" src="plug-in/mutiLang/zh-cn.js"></script>
    <script type="text/javascript" src="plug-in/jquery/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="plug-in/jquery/jquerysession.js"></script>
    <script type="text/javascript" src="plug-in/tools/dataformat.js"></script>
    <link id="easyuiTheme" rel="stylesheet" href="plug-in/easyui/themes/default/easyui.css" type="text/css"></link>
    <link rel="stylesheet" href="plug-in/easyui/themes/icon.css" type="text/css"></link>
    <link rel="stylesheet" type="text/css" href="plug-in/accordion/css/accordion.css">
    <script type="text/javascript" src="plug-in/easyui/jquery.easyui.min.1.3.2.js"></script>
    <script type="text/javascript" src="plug-in/easyui/locale/zh-cn.js"></script>
    <script type="text/javascript" src="plug-in/tools/syUtil.js"></script>
    <script type="text/javascript" src="plug-in/easyui/extends/datagrid-scrollview.js"></script>
    <script type="text/javascript" src="plug-in/My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" href="plug-in/tools/css/common.css" type="text/css"></link>
    <script type="text/javascript" src="plug-in/lhgDialog/lhgdialog.min.js"></script>
    <script type="text/javascript" src="plug-in/tools/curdtools_zh-cn.js"></script>
    <script type="text/javascript" src="plug-in/tools/easyuiextend.js"></script>
    <script type="text/javascript" src="plug-in/jquery-plugs/hftable/jquery-hftable.js"></script>
    <link rel="stylesheet" href="plug-in/jquery/jquery-autocomplete/jquery.autocomplete.css" type="text/css"></link>
    <script type="text/javascript" src="plug-in/jquery/jquery-autocomplete/jquery.autocomplete.min.js"></script>
    <link rel="stylesheet" href="plug-in/uploadify/css/uploadify.css" type="text/css"/>
    <script type="text/javascript" src="plug-in/uploadify/jquery.uploadify-3.1.min.js"></script>
</head>

<body>
<t:formvalid layout="" dialog="false" formid="formobj">
    <input type="hidden" id="serviceShi" value="${cbsService.city.territoryCode}">
    <input type="hidden" id="code" value="${code}">
    <div style="margin-top:10px;"><span style="font-weight: bold; margin-left:5px;">设备信息</span></div>
    <div class="line"></div>
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>序列号:</label>
            </td>
            <td width="30%">
                <input type="hidden" id="cbsServiceId" value="${cbsService.id}">
                <input type="hidden" id="sn" value="${cbsService.sn}">
                    ${cbsService.sn}
            </td>
            <td class="al_r" width="20%">
                <label>机型:</label>
            </td>
            <td width="30%">
                <input type="hidden" id="equipmentType" value="${cbsService.zyEquipmentSpareId.type.typeDesc}">
                    ${cbsService.zyEquipmentSpareId.type.typeDesc}
            </td>
        </tr>
        </tbody>
    </table>
    <div><span style="font-weight: bold;margin-left:5px;">申请备件</span>&nbsp;&nbsp;
        <a href="#" class="easyui-linkbutton l-btn" onclick="addEquipment()">添加</a>
    </div>
    <div class="line"></div>
    <div class="l-div" id="addEquTab">
        <div style="border-bottom: 1px solid #aeb5ae;" id="div">
            <table class="nobordertable noborder" style="border: none;" id="table" name="table">
                <tbody>
                <tr>
                    <td class="al_r" width="20%">
                        <span style="color:red;">*</span><label>备件类型:</label>
                    </td>
                    <td width="30%">
                        <input name="typeId" type="hidden" id="a"/>
                        <input class="inputxt" name="typeDes" id="w0" datatype="*" readonly="readonly" uuid="*"/>
                        <input class="button" value="选择" type="button" id="w" onclick="getTree(this)"/>
                    </td>
                    <td class="al_r" width="20%">
                        <span style="color:red;">*</span><label>备件号:</label>
                    </td>
                    <td width="30%">
                        <select name="itemId" id="witem" onchange="getItemDesc(this)" datatype="*" nullmsg="请填写备件号">
                            <option value="0">请选择</option>
                        </select>
                        <input name="item" id="item" type="text" style="display: none" datatype="*">
                        <span class="Validform_checktip"></span>
                        <label class="Validform_label" style="display: none;">备件号</label>
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%">
                        <label>备件描述:</label>
                    </td>
                    <td colspan="3">
                        <span class="color-red" id="span"></span>
                        <input type='text' id="itemDesc" name='itemDesc' style="display: none">
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%">
                        <span style="color:red;">*</span><label>数量:</label>
                    </td>
                    <td width="30%">
                        <input name="total"/>
                    </td>
                    <td class="al_r" width="20%">
                        <span style="color:red;">*</span><label>申请优先级:</label>
                    </td>
                    <td width="30%">
                        <select name="applyLayer">
                            <option value="1">低</option>
                            <option selected="selected" value="2">中</option>
                            <option value="3">高</option>
                            <option value="4">加急</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%"><label>备件说明:</label></td>
                    <td colspan="3">
                        <textarea name="memo" cols="50"></textarea></td>
                </tr>
                </tbody>
            </table>
            <div style="text-align: right;margin-bottom: 10px">
                <a href="#" class="easyui-linkbutton l-btn" onclick="del(this)">删除</a>
            </div>
        </div>
    </div>
    <div><span style="font-weight: bold;margin-left:5px;">故障备件信息</span>&nbsp;&nbsp;
        <a class="easyui-linkbutton l-btn" onclick="faultEquipment()">添加</a>
    </div>
    <div class="line"></div>
    <table class="ftable">
        <tbody id="faultEquipment">
        <tr>
            <th>备件类型</th>
            <th>备件号</th>
            <th>备件序列号</th>
            <th>备件二维码</th>
            <th>操作</th>
        </tr>
        </tbody>
    </table>
    <div style="margin-top:20px;"><span style="font-weight: bold;margin-left:5px;">收货人</span></div>
    <div class="line"></div>
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="15%">
                <label>是否自提:</label>
            </td>
            <td colspan="3">
                <input type="radio" name="radiobutton" value="是" onclick="getValue()"> 是
                <input type="radio" name="radiobutton" value="否" onclick="getValue()" checked> 否
            </td>
        </tr>
        <tr>
            <td class="al_r" width="15%">
                <span style="color:red;">*</span><label>姓名:</label>
            </td>
            <td width="43%">
                <input id="userName" name="userName" datatype="*" value="${cbsService.contactsName}"/>
                <span class="Validform_checktip"></span>
                <label class="Validform_label" style="display: none;">姓名</label>
            </td>
            <td class="al_r" width="10%">
                <span style="color:red;">*</span><label>电话:</label>
            </td>
            <td width="40%">
                <input id="phone" name="phone" datatype="*" value="${cbsService.contactsPhone}"/>
                <span class="Validform_checktip"></span>
                <label class="Validform_label" style="display: none;">电话</label>
            </td>
        </tr>
        <tr id="tr1">
            <td class="al_r" width="10%">
                <span style="color:red;">*</span><label>收货地址:</label>
            </td>
            <td width="40%">
                <select style="width: 43%" onchange="getShi()" id="sheng">
                    <option value="">请选择</option>
                    <c:forEach items="${tSTerritoryHql}" var="t">
                        <option value="${t.territoryCode}" ${t.id==cbsService.province.id?"selected":""}>${t.territoryName}</option>
                    </c:forEach>
                </select>
                <select style="width: 52%" id="shi">
                </select>
            </td>
            <td class="al_r" width="10%">
                <span style="color:red;">*</span><label>影院名称:</label>
            </td>
            <td width="40%">
                <input id="cinemaName" datatype="*" style="width:65%" value="${cbsService.zyCinemaName}"/>
                <span class="Validform_checktip"></span>
                <label class="Validform_label" style="display: none;">影院名称</label>
            </td>
        </tr>
        <tr id="tr2">
            <td></td>
            <td colspan="3" style="padding: 0 8px;"><input style="width:50%" id="address" datatype="*" nullmsg="请填写具体地址"
                                                           value="${cbsService.address}"/></td>
        </tr>
        <tr style="display: none" id="tr3">
            <td class="al_r"><label>自提仓库:</label></td>
            <td colspan="3">
                <select id="warehouse" onchange="getWarehouseAddress()">

                </select>
                &nbsp;&nbsp;
                <span id="span1"></span>
            </td>
        </tr>
        </tbody>
    </table>
    <div style="margin-top:20px;"><span style="font-weight: bold;margin-left:5px;">说明</span></div>
    <div class="line"></div>
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>申请理由:</label>
            </td>
            <td colspan="3">
                <select id="applyReason">
                    <c:forEach items="${TSTypeList}" var="tst">
                        <option value="${tst.typename}">${tst.typename}</option>
                    </c:forEach>
                </select>
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>上传附件:</label>
            </td>
            <td colspan="3">
                <input type="file" value="上传附件" id="fileUpload"/>&nbsp;&nbsp;
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%" valign="top">
                <label>处理描述:</label>
            </td>
            <td width="80%">
                <textarea style="width: 95%; height: 80px;" id="memo"></textarea>
            </td>
        </tr>
        </tbody>
    </table>
    <div style="text-align: center;margin-bottom: 10px;">
        <a class="easyui-linkbutton l-btn" onclick="addSparepartApply()">确认 </a>
    </div>
</t:formvalid>
</body>
<input type="hidden" name="type" id="type"> <%--type=1，代表是弹框弹出的备件申请--%>
</html>
<script type="text/javascript">

    function addEquipment() {
        $.ajax({
            url: "cbsServiceController.do?getUuid",
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (uuid) {
                var html = '<div style="border-bottom: 1px solid #aeb5ae;" id="' + uuid + 'div"><table class="nobordertable noborder" name="table" id="' + uuid + 't" style="border: none;">' +
                    '<tbody><tr><td class="al_r" width="20%"><span style="color:red;">*</span><label>备件类型:</label></td><td width="30%">' +
                    '<input name="typeId" type="hidden" id="' + uuid + '" />' +
                    '<input class="inputxt" name="typeDes" id="' + uuid + '0" readonly="readonly" uuid="*" />' +
                    '<input class="button" value="选择" type="button" id="' + uuid + '" onclick="getTree(this)"/>' +
                    '</td><td class="al_r" width="20%">' +
                    '<span style="color:red;">*</span><label>备件号:</label></td><td width="30%"><select name="itemId" id="' + uuid + 'item" onchange="getItemDesc(this)" datatype="*"><option>请选择</option></select><span class="Validform_checktip"></span>\n' +
                    '<label class="Validform_label" style="display: none;">备件号</label><input name="item" datatype="*" nullmsg="请填写备件号" id="' + uuid + 'in" type="text" style="display: none"></td>' +
                    '</tr><tr><td class="al_r" width="20%"><label>备件描述:</label></td><td colspan="3">' +
                    '<span class="color-red" id="' + uuid + 'span"></span><input type="text" id="' + uuid + 'itemDesc" name="itemDesc" style="display: none"></td></tr><tr><td class="al_r" width="20%">' +
                    '<span style="color:red;">*</span><label>数量:</label></td><td width="30%"><input name="total" /></td><td class="al_r" width="20%">' +
                    '<span style="color:red;">*</span><label>申请优先级:</label></td><td width="30%"><select name="applyLayer"><option value="1">低</option><option selected="selected"  value="2">中</option><option value="3">高</option><option value="4">加急</option></select>' +
                    '</td></tr><tr><td class="al_r" width="20%"><label>备件说明:</label></td><td colspan="3">' +
                    '<textarea name="memo" cols="50"></textarea></td></tr></tbody></table><div style="text-align: right;margin-bottom: 10px">' +
                    '<a href="#" class="easyui-linkbutton l-btn" onclick=delSparePart("' + uuid + '",this)><span class="l-btn-left"><span class="l-btn-text">删除</span></span></a><div></div>';
                console.log(html);
                $("#addEquTab").prepend(html);
            }
        });
    }

    function getTree(obj) {
        var uuid = obj.id;
        var cbsServiceId = $("#cbsServiceId").val();
        $.dialog({
            content: "url:cbsServiceController.do?goChooseEquipmentType&uuid=" + uuid + "&id=" + cbsServiceId,
            zIndex: 2100,
            title: '机型',
            lock: true,
            width: '300px',
            height: '400px',
            left: '85%',
            top: '65%',
            opacity: 0.4,
            init: function () {
                top.myWindow = window;
            },
        });
    }

    function delSparePart(uuid, obj) {
        $("#" + uuid + "div").remove();
    }

    function getItemDesc(obj) {
        if (obj.id == 'witem') {
            $.ajax({
                url: "cbsServiceController.do?getItemDesc",
                data: {
                    "id": obj.value,
                },
                cache: false,
                dataType: 'json',
                type: 'POST',
                error: function () {// 请求失败处理函数
                },
                success: function (data) {
                    $("#span").text(data.itemDesc);
                }
            });
        } else {
            var uuid = obj.id.substring(0, 32);
            $.ajax({
                url: "cbsServiceController.do?getItemDesc",
                data: {
                    "id": obj.value,
                },
                cache: false,
                dataType: 'json',
                type: 'POST',
                error: function () {// 请求失败处理函数
                },
                success: function (data) {
                    $("#" + uuid + "span").text(data.itemDesc);
                }
            });
        }
    }

    function faultEquipment() {
        $.ajax({
            url: "cbsServiceController.do?getUuid",
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (uuid) {
                var html = '<tr id="' + uuid + 'tr"><td><input name="type_id" type="hidden" id="' + uuid + '"/>' +
                    '<input class="inputxt" name="type_des" readonly="readonly" id="' + uuid + '0" datatype="*" />' +
                    '<input class="button" value="选择" type="button" id="' + uuid + '" onclick="getTree(this)"/></td>' +
                    '<td><select name="item_id" id="' + uuid + 'item"><option value="0">请选择</option></select><input name="itemm" id="' + uuid + 'in" type="text" style="display: none"></td>' +
                    '<td><input name="s_n" type="text"></td>' +
                    '<td><input name="equipment_ercode" type="text"></td>' +
                    '<td><a class="color-blue" onclick=delEquipment("' + uuid + '")>[删除]</a></td>' +
                    '</tr>';
                console.log(html);
                $("#faultEquipment").append(html);
            }
        });
    }

    function delEquipment(uuid) {
        $("#" + uuid + "tr").remove();
    }

    $(function () {
        getShi(serviceShi);
    })

    function getShi() {
        var serviceShi = $("#serviceShi").val();
        var sheng = $("#sheng").val();
        $.ajax({
            url: "cbsServiceController.do?getShi",
            data: {
                "sheng": sheng,
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (data) {
                $("#shi").html("");
                var html = "";
                html += "<option value=''>请选择</option>";
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i].territoryCode + "'>" + data[i].territoryName + "</option>"
                }
                $("#shi").append(html)
                $("#shi").find("option[value=" + serviceShi + "]").attr("selected", true);
            }
        });
    }

    function getValue() {
        var radiobutton = $("[name='radiobutton']:checked").val();
        if (radiobutton == '是') {
            $.ajax({
                url: "cbsServiceController.do?getWarehouse",
                cache: false,
                dataType: 'json',
                type: 'POST',
                error: function () {// 请求失败处理函数
                },
                success: function (data) {
                    var warehouseHql = data.warehouseHql;
                    $("#warehouse").html("");
                    var html = "";
                    html += "<option value=''>请选择</option>"
                    for (var i = 0; i < warehouseHql.length; i++) {
                        html += "<option value='" + warehouseHql[i].id + "' >" + warehouseHql[i].name + "</option>"
                    }
                    $("#warehouse").append(html);
                }
            });
            $("#tr1").hide();
            $("#tr2").hide();
            $("#tr3").show();
        } else {
            getShi();
            $("#tr1").show();
            $("#tr2").show();
            $("#tr3").hide();
        }
    }

    function getWarehouseAddress() {
        var id = $("#warehouse").val();
        var type = 1;
        $.ajax({
            url: "cbsServiceController.do?getWarehouse",
            data: {
                "type": type,
                "id": id
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (data) {
                var a = "";
                var tstList = data.tstList;
                var cbsWarehouse = data.cbsWarehouse;
                if (tstList != null) {
                    for (var i = 0; i < tstList.length; i++) {
                        a += tstList[i][3];
                    }
                    a += cbsWarehouse.address;
                    $("#span1").text(a);
                }
            }
        });
    }

    $(function () {
        var cbsServiceId = $("#cbsServiceId").val();
        $("#fileUpload").uploadify({
            buttonText: '上传照片',
            auto: true,
            progressData: 'speed',
            multi: true,
            height: 20,
            width: 60,
            overrideEvents: ['onDialogClose'],
            queueID: 'instructionfile',
            fileTypeDesc: '文件格式:',
            fileTypeExts: '*.*',
            /*fileTypeDesc: '支持格式:*.png',
            fileTypeExts: '*.png;*.jpg',*/ //控制可上传文件的扩展名，启用本项时需同时声明fileDesc
            // queueSizeLimit: '3',
            fileSizeLimit: '50MB',
            swf: 'plug-in/uploadify/uploadify.swf',
            uploader: 'cbsServiceController.do?fileUploadView&cbsServiceId=' + cbsServiceId + "&businessType=F",
            onUploadStart: function () {
                /*var a = $("[name='fileId']").length;
                if (a > 2) {
                    $('#fileUpload').uploadify('stop');
                    tip("最多上传三张照片")
                } else {
                    lockmask(true, '请稍等,导入中...');
                }*/
                lockmask(true, '请稍等,导入中...');
            },
            onUploadSuccess: function (file, data) {
                lockmask(false);
                var json = $.parseJSON(data).attributes;
                var html = '<p name="fileId" id="li_file_' + json.id + '"><span class="color-blue" id="' + json.id + '">' + json.name + '</span>&nbsp;&nbsp; ' +
                    '<span style="cursor: pointer;" onclick=\'delFile("' + json.id + '")\'>[删除]</span></p>';
                $("#fileUpload").after(html);
                tip("上传成功！");
            }, onFallback: function () {
                tip("您未安装FLASH控件，无法上传文件！请安装FLASH控件后再试");
            }, onSelectError: function (file, errorCode, errorMsg) {
                switch (errorCode) {
                    case -100:
                        tip("上传的文件数量已经超出系统限制的" + $('#fileUpload').uploadify('settings', 'queueSizeLimit') + "个文件！");
                        break;
                    case -110:
                        tip("文件 [" + file.name + "] 大小超出系统限制的50MB大小！");
                        break;
                    case -120:
                        tip("文件 [" + file.name + "] 大小异常！");
                        break;
                    case -130:
                        tip("文件 [" + file.name + "] 类型不正确！");
                        break;
                }
            }
        });

    });

    function delFile(id) {
        var flag = true;
        $.ajax({
            url: "cbsServiceController.do?delFile",
            data: {
                "id": id
            },
            cache: false,
            dataType: 'json',
            type: 'POST',
            async: false,
            success: function (data) {
                if (!data.success) {
                    flag = false;
                    tip(data.msg);
                } else {
                    tip(data.msg);
                    //隐藏标签
                    $("#li_file_" + id + "").remove();
                }
            }
        });
    }

    function addSparepartApply() {
        var fl = $("[name='fileId']").length;
        if (fl > 3) {
            tip("最多上传三张照片")
            return false;
        }
        var table = $("[name='table']");
        if (table.length == 0) {
            tip("请至少添加一个备件");
            return false;
        }
        var panduan = 0;
        $("[name='typeDes']").each(function () {
            if ($(this).val() == null || $(this).val() == "") {
                panduan = 1;
            }
        });
        if (panduan == 1) {
            tip("备件类型不能为空");
            return false;
        }

        $("[name='total']").each(function () {
            if (isNaN($(this).val())) {
                panduan = 4;
            }
        });
        if (panduan == 4) {
            tip("数量必须为数字");
            return false;
        }
        $("[name='total']").each(function () {
            if ($(this).val() == null || $(this).val() == "") {
                panduan = 3;
            }
        });
        if (panduan == 3) {
            tip("数量不能为空");
            return false;
        }
        var sheng = $("#sheng").val();
        var shi = $("#shi").val();
        if (sheng == '' || shi == '' || sheng == null || shi == null) {
            tip("收货地址不能为空");
            return false;
        }
        
        //调用formValidata 进行验证，并能阻止提交
        if (!form.check(true)) {
            form.submitForm(false);
            return false;
        }
        var code = $("#code").val();
        var obj = {};
        obj.radiobutton = $("[name='radiobutton']:checked").val();
        obj.sn = $("#sn").val();
        obj.equipmentType = $("#equipmentType").val();
        obj.userName = $("#userName").val();
        obj.phone = $("#phone").val();
        obj.cinemaName = $("#cinemaName").val();
        obj.applyReason = $("#applyReason").val();
        obj.memo = $("#memo").val();
        obj.seng = $("#sheng").val();
        obj.si = $("#shi").val();
        obj.warehouse = $("#warehouse").val();
        obj.address = $("#address").val();
        obj.serviceId = $("#cbsServiceId").val();
        obj.radiobutton = $("[name='radiobutton']:checked").val();
        var itemDescs = [];
        var x = 0;
        $("[name='itemDesc']").each(function () {
            itemDescs[x] = $(this).val();
            x++;
        });
        var typeIds = [];
        var m = 0;
        $("[name='typeId']").each(function () {
            typeIds[m] = $(this).val();
            m++;
        });
        var typeDess = [];
        var s = 0;
        $("[name='typeDes']").each(function () {
            typeDess[s] = $(this).val();
            s++;
        });
        var itemIds = [];
        var u = 0;
        $("[name='itemId']").each(function () {
            itemIds[u] = $(this).val();
            u++;
        });
        var items = [];
        var e = 0;
        $("[name='item']").each(function () {
            items[e] = $(this).val();
            e++;
        });
        var totals = [];
        var c = 0;
        $("[name='total']").each(function () {
            totals[c] = $(this).val();
            c++;
        });
        var applyLayers = [];
        var x = 0;
        $("[name='applyLayer']").each(function () {
            applyLayers[x] = $(this).val();
            x++;
        });
        var memos = [];
        var y = 0;
        $("[name='memo']").each(function () {
            memos[y] = $(this).val();
            y++;
        });
        var fileIds = [];
        var p = 0;
        $("[name='fileId']").each(function () {
            fileIds[p] = this.id.substr(8, 32);
            p++;
        });
        obj.itemDescs = itemDescs;
        obj.fileIds = fileIds;
        obj.typeIds = typeIds;
        obj.typeDess = typeDess;
        obj.itemIds = itemIds;
        obj.items = items;
        obj.totals = totals;
        obj.applyLayers = applyLayers;
        obj.memos = memos;
        var type_ids = [];
        var a = 0;
        $("[name='type_id']").each(function () {
            type_ids[a] = $(this).val();
            a++;
        });
        var type_dess = [];
        var b = 0;
        $("[name='type_des']").each(function () {
            type_dess[b] = $(this).val();
            b++;
        });
        var item_ids = [];
        var f = 0;
        $("[name='item_id']").each(function () {
            item_ids[f] = $(this).val();
            f++;
        });
        var itemms = [];
        var g = 0;
        $("[name='itemm']").each(function () {
            itemms[g] = $(this).val();
            g++;
        });
        var s_ns = [];
        var h = 0;
        $("[name='s_n']").each(function () {
            s_ns[h] = $(this).val();
            h++;
        });
        var equipment_ercodes = [];
        var j = 0;
        $("[name='equipment_ercode']").each(function () {
            equipment_ercodes[j] = $(this).val();
            j++;
        });
        obj.type_ids = type_ids;
        obj.type_dess = type_dess;
        obj.item_ids = item_ids;
        obj.itemms = itemms;
        obj.s_ns = s_ns;
        obj.equipment_ercodes = equipment_ercodes;
        if (code != 1) {
            lockmask(true);
            $.ajax({
                url: "cbsServiceController.do?addSparepartApply",
                data: obj,
                cache: false,
                dataType: 'json',
                type: 'POST',
                traditional: true,
                success: function (data) {
                    lockmask(false);
                    if (data.success) {
                        parent.window.tip("操作成功");
                        frameElement.api.close();
                    } else {
                        parent.window.tip("操作失败");
                        frameElement.api.close();
                    }
                },
            });
        } else {
            $.dialog({
                content: "url:cbsServiceController.do?dispatch&cbsServiceId=" + obj.serviceId,
                zIndex: 2100,
                title: '提示',
                lock: true,
                width: '400px',
                height: '200px',
                left: '50%',
                top: '50%',
                opacity: 0.4,
                init: function () {
                    top.myWindow = window;
                },
                button: [{
                    name: '确认',
                    callback: function () {
                        lockmask(true);
                        var csaAttention = $.session.get("csaAttention");
                        obj.csaAttention = csaAttention;
                        $.ajax({
                            url: "cbsServiceController.do?addSparepartApply",
                            data: obj,
                            cache: false,
                            dataType: 'json',
                            type: 'POST',
                            traditional: true,
                            error: function () {// 请求失败处理函数
                            },
                            success: function (data) {
                                if (data.success) {
                                    lockmask(false);
                                    $.session.remove("csaAttention");
                                    addOneTab('服务单管理', 'cbsServiceController.do?cbsService&type=2', "");
                                    frameElement.api.close();
                                }
                            }
                        });
                    },
                    focus: true
                }, {
                    name: '取消',
                    callback: function () {
                    }
                }]
            });
        }
    }

    function del(obj) {
        $("#div").remove();
    }

    var form = $("#formobj").Validform({
        ignoreHidden: true,
        postonce: true,
        showAllError: true,
        ajaxPost: true,
        tiptype: 3,
    })
</script>